package cc.rengu.igas.opms.core.service.trans.apppay;

import cc.rengu.igas.opms.common.constant.OpmsParamConstant;
import cc.rengu.igas.opms.common.enums.RespCodeEnum;
import cc.rengu.igas.opms.core.service.base.ManageService;
import cc.rengu.igas.opms.facade.request.EbankCustomerQueryRequest;
import cc.rengu.igas.opms.facade.response.EbankCustomerQueryResponse;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.common.constant.TreeNodeConstant;
import cc.rengu.oltp.service.common.entity.ChannelCallCfg;
import cc.rengu.oltp.service.common.enums.CheckResultEnum;
import cc.rengu.oltp.service.common.enums.TransStatusEnum;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.service.model.OrderInfo;
import cc.rengu.oltp.service.realize.TransCustomImpl;
import cc.rengu.oltp.utility.util.ConvertUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;

import java.util.List;

/**
 * 电子银行客户号查询
 * 收银台—>支付通道—>ESB
 * T00PM054
 *
 * @author fuyp
 * @date 2020/7/9.
 */
public class EbankCustomerQueryService extends ManageService implements TransCustomImpl {
    @Override
    protected Object bizBeforeCust() throws Exception {
        EbankCustomerQueryRequest ebankCustomerQueryRequest = new EbankCustomerQueryRequest();
        ConvertUtil.convertOutput(ebankCustomerQueryRequest);
        return ebankCustomerQueryRequest;
    }

    @Override
    protected BizResponse bizProcessCust(Object request) throws Exception {

        //获取请求数据
        EbankCustomerQueryRequest ebankCustomerQueryRequest = (EbankCustomerQueryRequest) request;
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String msgSrcId = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.MSG_SRC_ID);
        String rqId = ebankCustomerQueryRequest.getRqId();

        EbankCustomerQueryResponse ebankCustomerQueryResponse = new EbankCustomerQueryResponse();

        /* 调用esb手机银行 - 通过token获取网银客户号 */
        if (rqId.equals("A2") || rqId.equals("DB")) {

            /*准备请求报文 调起esb接口*/
            //TODO 根据TOKEN获取核心客户信息
        }
        /* 调用esb微信 - 通过token获取网银客户号 */
        else if (OpmsParamConstant.MBANK_CHANNEL_ID.equals(rqId) || OpmsParamConstant.O2OBANK_CHANNEL_ID.equals(rqId)) {

            //TODO 根据TOKEN获取客户号

        } else {
            rglog.error("rqId信息异常或不支持此渠道！");
            throw new BizException(RespCodeEnum.PARAM_ERROR.getRespCode(), RespCodeEnum.PARAM_ERROR.getRespDesc());
        }

        //组装响应
        ebankCustomerQueryResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        ebankCustomerQueryResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());

        BizResponse<EbankCustomerQueryResponse> bizResponse = new BizResponse<>();
        bizResponse.setRspSysId(AppParamConstant.SYS_ID);
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        bizResponse.setResult(ebankCustomerQueryResponse);
        return bizResponse;
    }

    @Override
    protected void bizAfterCust(Object response) throws Exception {
        BizResponse bizResponse = (BizResponse) response;
        EbankCustomerQueryResponse ebankCustomerQueryResponse = (EbankCustomerQueryResponse) bizResponse.getResult();
        ConvertUtil.convertInput(ebankCustomerQueryResponse);
    }

    @Override
    public ChannelCallCfg channelCallSceneDiscern(Object request, List<ChannelCallCfg> channelCallCfgList) throws Exception {
        return null;
    }

    @Override
    public CheckResultEnum channelCallPreCheck(Object request, ChannelCallCfg channelCallCfg, OrderInfo orderInfo) throws Exception {
        return null;
    }

    @Override
    public TransStatusEnum channelCallResultProc(Object request, ChannelCallCfg channelCallCfg, TransStatusEnum transStatusEnum, Object channelResponse, OrderInfo needUpdateOrderInfo) throws Exception {
        return null;
    }
}